﻿using System;
using System.Collections.Generic;
using System.Linq;
using Pap.Data.Abstraction.Utils;

namespace Pap.Data.LToS.Repositories
{
    /// <summary>
    /// 
    /// </summary>
    public class UserMessagesRepositoryImpl : IUserMessagesRepository
    {
        /// <summary>
        /// 
        /// </summary>
        private IDatabase _Database;

        /// <summary>
        /// Initializes a new instance of the <see cref="UserMessagesRepositoryImpl"/> class.
        /// </summary>
        /// <param name="database">The database.</param>
        public UserMessagesRepositoryImpl(IDatabase database)
        {

            this._Database = database;
        }

        /// <summary>
        /// Gets the user message by ID.
        /// </summary>
        /// <param name="UserMessageID">The user message ID.</param>
        /// <returns></returns>
        public IUserMessage GetUserMessageByID(Guid UserMessageID)
        {

            return _Database.UserMessages.SingleOrDefault(t => t.UserMessageID == UserMessageID);
        }

        /// <summary>
        /// Finds the user messages.
        /// </summary>
        /// <param name="Where">The where.</param>
        /// <returns></returns>
        public IEnumerable<IUserMessage> FindUserMessages(System.Linq.Expressions.Expression<Func<IUserMessage, bool>> Where)
        {

            return this._Database.UserMessages.Where(Where);
        }

        /// <summary>
        /// Creates the user message.
        /// </summary>
        /// <param name="UserMessage">The user message.</param>
        public void CreateUserMessage(IUserMessage UserMessage)
        {

            this._Database.Insert<IUserMessage>(UserMessage);
        }

        /// <summary>
        /// Deletes the user messages.
        /// </summary>
        /// <param name="Where">The where.</param>
        public void DeleteUserMessages(System.Linq.Expressions.Expression<Func<IUserMessage, bool>> Where)
        {
            this._Database.DeleteAll<IUserMessage>(this._Database.UserMessages.Where(Where));
        }
    }
}
